﻿using Microsoft.Xna.Framework;


namespace KineBall.GameLogic
{
    public class GameField
    {
        public Vector3[] rectangles;

        public float Width { get; set; }
        public float Height { get; set; }
        public float Depth { get; set; }

        public BoundingBox BoundingBox { get; set; }

        public BoundingBox BoundingBoxLeft { get; set; }
        public BoundingBox BoundingBoxRight { get; set; }
        public BoundingBox BoundingBoxDown { get; set; }
        public BoundingBox BoundingBoxUp { get; set; }
        public BoundingBox BoundingBoxBackward { get; set; }
        public BoundingBox BoundingBoxForward { get; set; }

        public GameField(Vector3 center, float width, float height, float depth)
        {
            Width = width;
            Height = height;
            Depth = depth;

            // Generate the position of the nine rectangles of the Game Field
            float rectanglesZDistance = depth / 9.0f;
            Vector3 rectanglePos = new Vector3(center.X, center.Y, center.Z + (rectanglesZDistance * 5));
            rectangles = new Vector3[9];

            for (int i = 0; i < 9; i++)
            {
                rectanglePos.Z -= rectanglesZDistance;
                rectangles[i] = rectanglePos;
            }

            // Bounding box for each side of the Game Field
            Vector3 min = new Vector3(-(width * 0.5f), -(height * 0.5f), -((depth * 0.5f) + 1));
            Vector3 max = new Vector3((width * 0.5f), (height * 0.5f), ((depth * 0.5f) + 1));
            BoundingBox = new BoundingBox(min, max);

            min = new Vector3(-((width * 0.5f) + 0.5f), -(height * 0.5f), -((depth * 0.5f) + 1));
            max = new Vector3(-(width * 0.5f), (height * 0.5f), ((depth * 0.5f) + 1));
            BoundingBoxLeft = new BoundingBox(min, max);

            min = new Vector3((width * 0.5f), -(height * 0.5f), -((depth * 0.5f) + 1));
            max = new Vector3(((width * 0.5f) + 0.5f), (height * 0.5f), ((depth * 0.5f) + 1));
            BoundingBoxRight = new BoundingBox(min, max);

            min = new Vector3(-(width * 0.5f), -((height * 0.5f) + 0.5f), -((depth * 0.5f) + 1));
            max = new Vector3((width * 0.5f), -(height * 0.5f), ((depth * 0.5f) + 1));
            BoundingBoxDown = new BoundingBox(min, max);

            min = new Vector3(-(width * 0.5f), (height * 0.5f), -((depth * 0.5f) + 1));
            max = new Vector3((width * 0.5f), ((height * 0.5f) + 0.5f), ((depth * 0.5f) + 1));
            BoundingBoxUp = new BoundingBox(min, max);

            min = new Vector3(-(width * 0.5f), -(height * 0.5f), -((depth * 0.5f) + 1.5f));
            max = new Vector3((width * 0.5f), (height * 0.5f), -((depth * 0.5f) + 1));
            BoundingBoxBackward = new BoundingBox(min, max);

            min = new Vector3(-(width * 0.5f), -(height * 0.5f), ((depth * 0.5f) + 1));
            max = new Vector3((width * 0.5f), (height * 0.5f), ((depth * 0.5f) + 1.5f));
            BoundingBoxForward = new BoundingBox(min, max);
        }
    }
}
